<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<header th:replace="admin/header::header-fragment">
</header>
<body>
<shiro:user>
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <button class="layui-btn layuiadmin-btn-comm" data-type="batchdel">删除</button>
        </div>
        <table id="LAY-app-content-comm" lay-filter="LAY-app-content-comm" class="demo"></table>
        <script type="text/html" id="table-content-com">
<!--          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>-->
          <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
      </div>
    </div>
  </div>
  </shiro:user>
  <shiro:guest>
    <footer th:replace="admin/nologin::header-fragment">
    </footer>
  </shiro:guest>
  <script src="layuiadmin/layui/layui.js"></script>
  <script>
  layui.config({
    base: 'layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'contlist', 'table'], function(){
    var $ = layui.$
    ,form = layui.form
    ,table = layui.table;
    
    
    //监听搜索
    form.on('submit(LAY-app-contcomm-search)', function(data){
      var field = data.field;
    });

    table.render({
      elem: '.demo'
      ,url: 'admin/allLog',
      page: true //开启分页
      ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
      ,defaultToolbar:false

      ,title: '用户数据表'
      ,cols: [
        [
          {type: 'checkbox',width:40},
          {field:'logid', title:'日志ID', width:100,align:'center',unresize:true},
          {field:'logname', title:'用户名', width:120,align:'center',unresize:true},
          {field:'logip', title:'日志IP', width:200,align:'center',unresize:true},
          {field:'logtime', title:'日志时间', width:240,align:'center',unresize:true,templet: "<div>{{layui.util.toDateString(d.commentCreateTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
          {field:'right', title:'操作',toolbar:'#table-content-com',unresize:true, align:'center',width: 220}
        ]
      ]
      ,limits: [5,10,20,50]  //每页条数的选择项，默认：[10,20,30,40,50,60,70,80,90]。
      ,limit: 5 //每页默认显示的数量
      ,parseData: function(res) { //res 即为原始返回的数据
        return {
          "code": 0, //解析接口状态
          "msg": "", //解析提示文本
          "count": res.count,
          data: res.data.items //解析数据列表
        };
      }
    });

    form.on('switch(Status)', function(obj){
      var commentId = this.value;
      var commentStatus = obj.elem.checked?1:0;
      //请求接口
      $.post('admin/updateCommentStatus',{
        "commentId":commentId,
        "commentStatus":commentStatus
      },'json');
    });
    //点击事件
    var active = {
      batchdel: function(){
        var checkStatus = table.checkStatus('LAY-app-content-comm')
        ,checkData = checkStatus.data; //得到选中的数据

        if(checkData.length === 0){
          return layer.msg('请选择数据');
        }
      
        layer.confirm('确定删除吗？', function(index) {
          $.ajax({
            url:'admin/deleteLog',
            data:{"delete":JSON.stringify(checkData)},
            dataType:'json',
            method:'post',
            success:function (res) {
              if (res.success){
                layer.msg('删除成功', {
                  offset: '15px'
                  ,icon: 1
                  ,time: 1000
                });
              }else {
                layer.msg('删除失败', {
                  offset: '15px'
                  ,icon: 1
                  ,time: 1000
                });
              }
              table.reload('LAY-user-manage');
            }
            ,error: function(){
              layer.alert('系统错误，请联系管理员！', {
                icon: 2,
                skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
              });
            }
          });

          table.reload('LAY-app-content-comm');
        });
      }
    }

    //监听行工具栏
    table.on('tool(LAY-app-content-comm)',function (obj) {
      //获取行数据
      var data = obj.data;
      //点击删除
      if (obj.event === 'del'){
        layer.confirm('确定删除吗？', function(index){
          $.ajax({
            url:'admin/deleteByIdLog',
            data:{"logid":data.logid},
            dataType:'json',
            method:'post',
            success:function (res) {
              if (res.success){
                layer.msg('删除成功', {
                  offset: '15px'
                  ,icon: 1
                  ,time: 1000
                });
              }else {
                layer.msg('删除失败', {
                  offset: '15px'
                  ,icon: 1
                  ,time: 1000
                });
              }
              table.reload('LAY-app-content-comm');
            }
            ,error: function(){
              layer.alert('系统错误，请联系管理员！', {
                icon: 2,
                skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
              });
            }
          });
          layer.close(index);
        });
      }
    })

    $('.layui-btn.layuiadmin-btn-comm').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  </script>
</body>
</html>

